package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhangtai.modules.entity.system.RoleEntity;
import com.zhangtai.modules.entity.system.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 系统用户
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-06-22 00:28:55
 */
@Mapper
public interface UserDao extends BaseMapper<UserEntity> {

    @Select("select m.perms from sys_menu m, sys_user u, sys_user_role ur, sys_role_menu rm\n" +
            "        where u.user_id = #{userId} and u.user_id = ur.user_id\n" +
            "          and ur.role_id = rm.role_id and rm.menu_id = m.menu_id and m.is_delete=0 ")
    List<String> findPermsByUserId(@Param("userId") Long userId);

    @Select("SELECT r.* FROM sys_role r, sys_user_role ur WHERE r.role_id = ur.role_id  and  ur.user_id =  #{userId}")
    List<RoleEntity> listRolesByUserId(@Param("userId") Long userId);

    /**
     * 根据用户id查找菜单
     * @param userId
     * @return
     */
    @Select("select m.url from sys_menu m, sys_user u, sys_user_role ur, sys_role_menu rm\n" +
            "        where u.user_id = #{userId} and u.user_id = ur.user_id\n" +
            "          and ur.role_id = rm.role_id and rm.menu_id = m.menu_id and m.is_delete=0 and m.type=1")
    List<String> findMenuByUserId(@Param("userId") Long userId);


}
